草庐IT

java - 实现类或导入类java

全部标签

import - Golang 导入问题

我正在尝试使用导入包供内部使用,但遇到了一些问题。我的目录结构如下所示:app/model/file1.gofile2.go...main.go当我尝试构建程序时,出现如下所示的错误:/usr/local/go/src/pkg/model(from$GOROOT)我希望能够在应用程序的任何其他程序中调用模型程序,只需使用:import"app/model"在执行此操作时,我有哪些选择? 最佳答案 你从GOPATH级别导入..你所有的包都应该放在那里。例如,假设您的应用程序在这里:$GOPATH/src/dtrinh100/app/.

go - 传递实现带有指针接收器的接口(interface)的对象

我知道这与Scale采用指针接收器这一事实有关。但我不明白我需要如何编写PrintArea,所以这行得通。packagemainimport("fmt")typeShapeinterface{Scale(numfloat64)Area()float64}typeSquarestruct{edgefloat64}func(s*Square)Scale(numfloat64){s.edge*=num}func(sSquare)Area()float64{returns.edge*s.edge}funcPrintArea(sShape){fmt.Println(s.Area())}funcm

data-structures - 链表实现的指针问题

尝试使用简单的addToLast函数(将新节点添加到链表的末尾)而不是使用内置列表来实现LinkedList)下面是代码(删除了我用于调试的打印语句):packagemainimport"fmt"varfirst*LinkvarlastLinkfuncmain(){AddToLast(10)AddToLast(20)}funcAddToLast(dint){iffirst==nil{last=Link{d,new(Link)}first=&last}else{last.next=&Link{d,new(Link)}last=*last.next}}typeLinkstruct{data

go - MessageImpl 没有实现 Message

在golang中,我有以下编译错误:cannotusem(typeMessageImpl)astypeMessageinassignment:MessageImpldoesnotimplementMessage(missingFirstLinemethod)使用以下代码:typeMessageinterface{FirstLine()string/*someothermethoddeclarations*/}typeMessageImplstruct{headers[]Header/*someotherfields*/}typeRequeststruct{MessageImpl/*so

reflection - 查找对象支持的所有导入接口(interface)

我有一个类似os.Stdout的对象,我想知道它是否支持我平台上的io.WriteCloser。我可以获得我的对象的类型,但它没有告诉我任何关于接口(interface)的信息。packagemainimport("fmt";"reflect";"os")funcmain(){fmt.Println(reflect.TypeOf(os.Stdout))}此代码将*os.File打印到控制台。如果os.File匹配io.WriteCloser方法,我可以手动查找,但我很想知道该对象支持的所有接口(interface)。 最佳答案 这不

导入且未使用 : as, 未定义

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭3个月前。Improvethisquestion我将文件重命名为File,并将moetemplate重命名为htmlparts然后去构建./router.go:8:importedandnotused:"github.com/golangframework/File"asfile./router.go:11:importedandnotused

go - 导入 `github.com/influxdb/influxdb/client/v2` 包时缺少符号

在Golang的谷歌云上设置网络套接字,并导入在我的本地机器上运行良好的代码在云上不起作用。我有:import"github.com/influxdb/influxdb/client/v2"已经跑了goget"github.com/influxdb/influxdb/client/v2"在运行gorunserver.go时我得到:#command-line-arguments./pi_server.go:47:undefined:client.NewClient./pi_server.go:47:undefined:client.Config完整代码如下,不包括const声明和html

go - 检查 Go 导入路径是否为本地

有没有一种编程方式(除了手动路径解析)来检查Go中的导入路径是否是本地的?我可以手动完成,但我更愿意避免错误的实现。 最佳答案 使用build.IsLocalImport确定导入路径是否为本地路径。IsLocalImportreportswhethertheimportpathisalocalimportpath,like".","..","./foo",or"../foo". 关于go-检查Go导入路径是否为本地,我们在StackOverflow上找到一个类似的问题:

go - 从其他包导入的结构未定义

这是我的菜鸟问题。我的models/model.go中有这个结构packagemodelsimport("time""gopkg.in/mgo.v2/bson")typeHorsestruct{Idbson.ObjectId`bson:"_id,omitempty"`TitlestringDescriptionstringCreatedOntime.TimeCreatorstringVisitsintScoreint}在我的controllers/crud.go中,我尝试使用Horse结构packagecontrollersimport("html/template""log""net

go - Go中如何实现依赖注入(inject)

我正在将应用程序从Play(Scala)移植到Go并想知道如何实现依赖注入(inject)。在Scala中,我使用了蛋糕模式,而在Go中,我实现了一个DAO接口(interface)以及一个Mongo实现。下面是我如何尝试实现一种模式,让我可以根据需要更改DAO实现(例如测试、不同的数据库等):1。实体.gopackagemodelsimport("time""gopkg.in/mgo.v2/bson")type(Entitystruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`CreatedAttime.Time